<?php
/**
 * Formulário padrão
 */
class App_Form_Pessoa extends Voitech_Form
{
	public function __construct($options=array())
	{
		parent::__construct($options);
		
		$this->setAttribs(array('name'=>'frmCadastroPessoa', 'id'=>'frmCadastroPessoa', 'class'=>'form last-child'));
		
		// add id element
                $this->addElement('hidden', 'co_pessoa');

                // remove id's decorators
                $this->getElement('co_pessoa')
                    ->removeDecorator('DtDdWrapper')
                    ->removeDecorator('HtmlTag')
                    ->removeDecorator('Label');
		
		$noPessoa 	= new Zend_Form_Element_Text( 'no_pessoa' );
		$noPessoa->setLabel( 'Pessoa:' )
				 ->setAttribs( array('size'=>'55') )
		         ->addFilter( new Zend_Filter_StringTrim() )
				 ->addValidator( new Zend_Validate_StringLength( array( 'min'=>'4', 'max'=>'155' ) ) )
		         ->setDecorators( $this->_decoratorDefault )
				 ->setRequired( true );
		$this->addElement( $noPessoa );	
		
		$nuCpf = new Zend_Form_Element_Text( 'nu_cpf' );
		$nuCpf->setLabel( 'Cpf:' )
			   ->setAttribs( array( 'size'=>'15', 'maxlength'=>'11' ) )
			   ->addFilter( new Zend_Filter_StringTrim() )
			   ->addFilter( new Zend_Filter_Alnum() )
			   ->addValidator( new Zend_Validate_StringLength( array( 'min'=>'11', 'max'=>'11' ) ) )
			   //->addValidator( new Voitech_Validate_Cpf() )
			   ->addValidator( new Zend_Validate_Alnum() )
			   ->setDecorators( $this->_decoratorDefault )
			   ->setRequired( true );
		$this->addElement( $nuCpf );
		
		$nuRg = new Zend_Form_Element_Text( 'nu_rg' );
		$nuRg->setLabel( 'Rg:' )
		            ->setAttribs( array( 'size'=>'15', 'maxlength'=>'20' ) )
		            ->addFilter( new Zend_Filter_StringTrim() )
		            ->addFilter( new Zend_Filter_Alnum() )
		            ->addValidator( new Zend_Validate_Alnum() )
		            ->addValidator( new Zend_Validate_StringLength( array( 'min'=>'4', 'max'=>'20' ) ) )
		            ->setDecorators( $this->_decoratorDefault )
		            ->setRequired( true );		
		$this->addElement( $nuRg );
                
                $dsEndereco = new Zend_Form_Element_Text( 'ds_endereco' );
		$dsEndereco->setLabel( 'Endereço:' )
			   ->setAttribs( array( 'size'=>'60' ) )
			   ->addFilter( new Zend_Filter_StringTrim() )
			   ->addFilter( new Zend_Filter_Alnum() )
			   ->setDecorators( $this->_decoratorDefault );
		$this->addElement( $dsEndereco );
		
		$nuTelefone = new Zend_Form_Element_Text( 'nu_telefone' );
		$nuTelefone->setLabel( 'Telefone:' )
		            ->setAttribs( array( 'size'=>'15', 'maxlength'=>'20' ) )
		            ->addFilter( new Zend_Filter_StringTrim() )
		            ->addFilter( new Zend_Filter_Alnum() )
		            ->setDecorators( $this->_decoratorDefault );		
		$this->addElement( $nuTelefone );
                                
                $buttonCancelar = new Zend_Form_Element_Button('Cancelar');
		$buttonCancelar->setAttribs( array('class'=> 'first-child last-child','style'=>'float:left;margin-top: 17px', 'id' => 'btnCancelar' ) )
		           ->removeDecorator( 'label' );
		$this->addElement( $buttonCancelar );

		$buttonCdst = new Zend_Form_Element_Button('Salvar');
		$buttonCdst->setAttribs( array('class'=> 'first-child last-child','style'=>'float:right; margin-top: 17px', 'id' => 'btnSalvar' ) )
		           ->removeDecorator( 'label' );
		
		$this->addElement( $buttonCdst );		
		$this->addDisplayGroup(array('no_pessoa','nu_cpf','nu_rg','ds_endereco','nu_telefone','Cancelar','Salvar'),'Cadastro',array('legend' => 'Formulario de cadastro de pessoa', 'class'=>'grey-bg first-child last-child fieldset-with-legend fieldset-with-legend-first-child'));
	}
}